﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ProjectVLIB.VOL;
using ProjectVLIB.DAL;

namespace ProjectVLIB.BLL
{
    class LoaiHangBL
    {
        private DataAccess dataAccess;
        public LoaiHangBL()
        {
            dataAccess = new DataAccess();
        }

        //Thêm
        public bool insertLoaiHang(LoaiHang obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@TenLoaiHang",SqlDbType.NVarChar){Value = obj.TenLoaiHang};

            string strSql = "INSERT INTO tbl_LoaiHang(TenLoaiHang) VALUES (@TenLoaiHang)";
            dataAccess.Execute(strSql);

            return true;
        }

        //Xóa
        public bool deleteLoaiHang(LoaiHang obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaLoaiHang", SqlDbType.Int) { Value = obj.MaLoaiHang };

            string strSql = "DELETE FROM tbl_LoaiHang WHERE MaLoaiHang = @MaLoaiHang";
            dataAccess.Execute(strSql);
            return true;
        }

        //Sửa
        public bool updateLoaiHang(LoaiHang obj)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@MaLoaiHang", SqlDbType.Int) { Value = obj.MaLoaiHang };
            param[1] = new SqlParameter("@TenLoaiHang", SqlDbType.NVarChar) { Value = obj.TenLoaiHang };

            string strSql = "UPDATE tbl_LoaiHang SET TenLoaiHang = @TenLoaiHang WHERE MaLoaiHang = @MaLoaiHang";
            dataAccess.Execute(strSql);
            return true;
        }

        //Tìm
        public DataTable searchIDLoaiHang(LoaiHang obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaLoaiHang", SqlDbType.Int) { Value = obj.MaLoaiHang };

            string strSql = "SELECT * FROM tbl_LoaiHang WHERE MaLoaiHang = @MaLoaiHang";
            return dataAccess.GetData(strSql,param);
        }
    }
}
